package com.hqyj.springBoot.modules.test.dao;

import com.hqyj.springBoot.modules.test.entity.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CountryDao {

    @Select("select * from test_country where country_id = #{countryId}")
    @Results(id = "countryResult",value = {
            @Result(column = "country_id",property = "countryId"),
            @Result(column = "country_id",property = "cities",
                javaType = List.class,
                many = @Many(select = "com.hqyj.springBoot_01.modules.test.dao." +
                        "CityDao.getCityByCountryId")
            )
    })
    Country getCountryByCountryId(int countryId);

    @Select("select * from test_country where country_name = #{countryName} " +
            "and local_country_name = #{localCountryName}")
    @ResultMap(value = "countryResult")//通过结果集的ID来拿到对应方法的返回结果
    Country getCountryByCountryNameAndLocalCountryName(String countryName,String localCountryName);
}
